﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BitPortal.Business;
using BitPortal.Models;
using BitPortal.Utils;

namespace BitPortal.Modules.ScrollAdvertise
{
    public partial class ScrollAdvertise : Controls.BaseUserControl
    {
        public int LeftGalleryID { set; get; }
        public int RightGalleryID { set; get; }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void OnInit(EventArgs e)
        {
            (this.Page as Controls.BaseFrontendPage).IncludeScriptFile("/Modules/ScrollAdvertise/Adv.js");
            base.OnInit(e);
            LeftGalleryID = ReferenceModule.GetModuleConfig("LeftGalleryID").ToInt32TryParse();
            RightGalleryID = ReferenceModule.GetModuleConfig("RightGalleryID").ToInt32TryParse();
            LeftAdContent.Controls.Clear();
            var g1 = GalleryBLL.GetByID(LeftGalleryID);
            if (g1 != null)
            {
                foreach (MediasInGallery m in g1.MediasInGalleries)
                {
                    ShowBanner c = (ShowBanner)LoadControl("~/Modules/ShowBanner.ascx");
                    c.Url = m.Media.MediaURL;
                    c.TargetURL = m.TargetURL;
                    c.OpenMode = "_blank";
                    LeftAdContent.Controls.Add(c);
                }
            }
            RightAdContent.Controls.Clear();
            var g2 = GalleryBLL.GetByID(RightGalleryID);
            if (g2 != null)
            {
                foreach (MediasInGallery m in g2.MediasInGalleries)
                {
                    ShowBanner c = (ShowBanner)LoadControl("~/Modules/ShowBanner.ascx");
                    c.Url = m.Media.MediaURL;
                    c.TargetURL = m.TargetURL;
                    c.OpenMode = "_blank";
                    RightAdContent.Controls.Add(c);

                }
            }
        }
    }
}